//
//  settingViewController.m
//  One Construction
//
//  Created by apple on 2019/9/7.
//  Copyright © 2019 apple. All rights reserved.
//

#import "settingViewController.h"
#import "ViewController.h"
#import "privacyViewController.h"
#import "aboutUsViewController.h"
@interface settingViewController ()
@property(nonatomic,strong)UIButton *lyoutBtn;
@end
@implementation settingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor colorWithRed:246/255.0 green:246/255.0 blue:246/255.0 alpha:1.0];
    self.navigationItem.title = @"设置";
    [self setUpView];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (void)setUpView{
    UIView *firstView = [[UIView alloc]initWithFrame:CGRectMake(10, AppNavitionHright+10, ScreenWidth-20, 50)];
    [self.view addSubview:firstView];
    [self addView:firstView lableText:@"应用分享"];
    firstView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickFirstView)];
    [firstView addGestureRecognizer:tap];
    
    
    UIView *secondView = [[UIView alloc]initWithFrame:CGRectMake(10, firstView.frame.origin.y+firstView.frame.size.height+10, ScreenWidth-20, 50)];
    [self.view addSubview:secondView];
    [self addView:secondView lableText:@"隐私政策"];
    secondView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickSecondView)];
    [secondView addGestureRecognizer:tap1];
    secondView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap2= [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickSecondView)];
    [secondView addGestureRecognizer:tap2];
    
    
    UIView *threeView = [[UIView alloc]initWithFrame:CGRectMake(10, secondView.frame.origin.y+secondView.frame.size.height+10, ScreenWidth-20, 50)];
    [self.view addSubview:threeView];
    [self addView:threeView lableText:@"关于我们"];
    threeView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap3= [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickThreeView)];
    [threeView addGestureRecognizer:tap3];
    
    [self.view addSubview:self.lyoutBtn];
    [self.lyoutBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(10);
        make.right.mas_offset(-10);
        make.height.mas_equalTo(50);
        make.top.mas_equalTo(threeView.mas_bottom).mas_equalTo(10);
    }];
    
    [self.lyoutBtn addTarget:self
                      action:@selector(clickLyoutBtn) forControlEvents:UIControlEventTouchUpInside];
    
    
}
- (void)clickFirstView{
   
    NSString *titel = @"快来和我一起加入吧~";
   
    UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:@[titel] applicationActivities:nil];
    controller.completionWithItemsHandler = ^(UIActivityType  _Nullable activityType, BOOL completed, NSArray * _Nullable returnedItems, NSError * _Nullable activityError) {
        
    };
    NSArray *regectArr = @[UIActivityTypePostToWeibo,UIActivityTypePostToFacebook];
    controller.excludedActivityTypes = regectArr;
    [self presentViewController:controller animated:YES completion:nil];
    
    
    
}
- (void)clickSecondView{

    privacyViewController *pr = [[privacyViewController alloc]init];
    [self.navigationController pushViewController:pr animated:YES];
    
    
    
}
- (void)clickThreeView{
  
    aboutUsViewController *ab =[[aboutUsViewController alloc]init];
    [self.navigationController pushViewController:ab animated:YES];
    
    
}
- (void)clickLyoutBtn{
    if ([User sharedUUser].login == YES) {
        if ([User sharedUUser].isLogout) {
            NSLog(@"已经退出登录");
             [ProgressHUD showText:@"已退出登录" icon:[UIImage imageNamed:@""] mode:MBProgressHUDModeText onView:self.view duration:1.0];
            
        }
    }
    
    else{
        [ProgressHUD showText:@"请先登录" icon:[UIImage imageNamed:@""] mode:MBProgressHUDModeText onView:self.view duration:1.0];
        
//        ViewController *vc =[[ViewController alloc]init];
//        [self.navigationController pushViewController:vc animated:YES];
        
        
        
        
    }
}
- (void)addView:(UIView *)viewcc lableText:(NSString *)labletext{
    viewcc.layer.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0].CGColor;
    viewcc.layer.cornerRadius = 10;
    viewcc.layer.shadowColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.05].CGColor;
    viewcc.layer.shadowOffset = CGSizeMake(0,1);
    viewcc.layer.shadowOpacity = 1;
    viewcc.layer.shadowRadius = 2;
    
    myLable *lable = [[myLable alloc]initWithFrame:CGRectMake(22, 12, 100, 25)];
    [lable setLabletextColor:[UIColor blackColor] Text:labletext TextFont:18];
    [viewcc addSubview:lable];
}

- (UIButton *)lyoutBtn{
    if (!_lyoutBtn) {
        
        _lyoutBtn = [[UIButton alloc]init];
        [_lyoutBtn setTitle:@"退出登录" forState:UIControlStateNormal];
        _lyoutBtn.backgroundColor =  [UIColor colorWithRed:31/255.0 green:78/255.0 blue:196/255.0 alpha:1.0];
        [_lyoutBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _lyoutBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
        
        
    }
    return _lyoutBtn;
    
}
@end
